package com.janko.springbootbase.controller;

import com.janko.services.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * @Author nyk
 * @Date 2021/6/25 15:29
 * @Version 1.0
 * @Desc  页面交互使用
 */
@Controller
public class HelloController {
    @Value("${custom.vv}")
    private String vv;

    @RequestMapping(value="/hello")
    //注意这儿没有@responseBody
    public String welcome(ModelMap map){
        Date date = new Date();
        //获取配置文件中的信息vv
        System.out.println(vv);
        //传到template模板中（会把模板中能找到的所有的ftl文件中的名称都替换掉）
        map.addAttribute("vv", date.toString());
        //返回页面hello.ftl
        return "hello";
    }

    @Autowired
    private DemoService demoService;


    @RequestMapping(value="/democonfig")
    @ResponseBody
    public String demoProperties(){
        return demoService.getInstances();
    }
}
